layui.define([ 'form', 'laydate', 'table','leaveMsgApi' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var leaveMsgApi=layui.leaveMsgApi;
	var leaveMsgTable = null;
	
	var view ={
		
		init:function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#searchForm"),leaveMsgTable)
			}
			
			
		},
		initTable:function(){
			leaveMsgTable = table.render({
				elem : '#leaveMsgTable',
				height : Lib.getTableHeight(2),
				method : 'post',
				url : Common.ctxPath + '/admin/leavemsg/list.json' //数据接口
				,page : Lib.tablePage //开启分页
				,limit : 10,
				cols : [ [ //表头
				{
					type : 'checkbox',
					fixed:'left',
				}, {
					field : 'id',
					title : 'id',
					width : 80,
					fixed:'left',
					sort : true
				}, {
					field : 'openid',
					title : '反馈人openid',
					width : 150
				}, {
					field : 'phone',
					title : '反馈人手机',
					width : 120
				}, {
					field : 'name',
					title : '反馈人姓名',
					width : 120
				}, {
					field : 'content',
					title : '反馈内容',
					width : 150
				}, {
					field : 'type',
					title : '反馈类型',
					width : 120
				}, {
					field : 'createTime',
					title : '反馈时间',
					width : 120,
					templet:function(d){
						return Common.getDate(d.createTime);
					},
					sort : true
				}, {
					field : 'filesPath',
					title : '反馈附件',
					width : 150,
					sort : true
				}, {
					field : 'creator',
					title : '处理人',
					width : 120,
					sort : true
				}, {
					field : 'dealTime',
					title : '处理时间',
					width : 120,
					templet:function(d){
						return Common.getDate(d.dealTime);
					},
					sort : true
				}, {
					field : 'status',
					title : '处理状态',
					width : 120,
					sort : true
				},
				 {
					field : 'note',
					title : '处理意见',
					width : 120,
					sort : true
				}

				] ]

			});
		},
		
		initSearchForm:function(){
			Lib.initSearchForm( $("#searchForm"),leaveMsgTable,form);
		},
		initToolBar:function(){
			toolbar = {
					edit : function() { //获取选中数目
						var data = Common.getOneFromTable(table,"leaveMsgTable");
						if(data==null){
							return ;
						}
						var url = "/admin/leavemsg/edit.do?id="+data.id;
						Common.openDlg(url,"反馈管理>编辑");
					},
					view : function() { //获取选中数目
						var data = Common.getOneFromTable(table,"leaveMsgTable");
						if(data==null){
							return ;
						}
						var url = "/admin/leavemsg/edit.do?id="+data.id;
						Common.openDlg(url,"反馈管理>查看");
					},
					del : function() { 
						layui.use(['del'], function(){
							  var delView = layui.del
							  delView.delBatch();
						});
					},
					exportLeaveMsg:function(){
					    Common.openConfirm("确认要导出这些反馈信息?",function(){
					        leaveMsgApi.exportLeaveMsg($("#searchForm"),function(fileId){
					           Lib.download(fileId);
					        })
		                })

                    }
				};
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	}

	 exports('index',view);
	
});